﻿using Grow.Json;
using Grow.Module;
using Grow.Module.Service;
using Grow.Rest.CreateRest;
using Grow.Rest.Http.CreateRest;
using Microsoft.Extensions.DependencyInjection;

namespace Grow.Rest.Http
{
    public abstract class RestHttpModuleBase : ModuleBase, IRestModule
    {
        public override ModuleLevel Level => ModuleLevel.Framework;

        public override void AddDependModule(IDependModuleBuilder dependModuleBuilder)
        {
            _ = dependModuleBuilder.AddDependModule<IJsonModule>();
        }


        public override void AddService(IServiceContainer serviceContainer)
        {
            CreateRestBuilder createRestBuilder = new(serviceContainer);
            CreateRest(createRestBuilder);
            serviceContainer.BuilderManager.SetBuilder<ICreateRestBuilder>(createRestBuilder);

            _ = serviceContainer.ServiceCollection.AddHttpClient();
            _ = serviceContainer.ServiceCollection.AddTransient<IRestClient, RestClient>();
        }

        public abstract void CreateRest(ICreateRestBuilder createRestBuilder);

        public override void UseService(IServiceContext serviceContext)
        {
        }
    }
}
